Health outcome
# renderPrint({
# input[["outcome_choice"]]
# })
#renderPlotly(
walkability_clean %>%
filter(!is.na(state) &
state == "New York" &
!is.na(nat_walk_ind)
) %>%
group_by(county, measure_id) %>%
summarise(walk = mean(nat_walk_ind),
outcome = mean(data_value)) %>%
mutate(
measure_id = replace(measure_id, measure_id == "HIGHCHOL", "High cholesterol"),
measure_id = replace(measure_id, measure_id == "PHLTH", "Poor physical health"),
measure_id = replace(measure_id, measure_id == "MHLTH", "Poor mental health"),
measure_id = replace(measure_id, measure_id == "LPA", "No leisure physical activity"),
measure_id = replace(measure_id, measure_id == "BPHIGH", "High blood pressure")
) %>%
plot_ly(x = ~county,
y = ~outcome, color = ~measure_id,
type = "bar") %>%
add_trace(x = ~walkability_tidy$county,
y = ~walkability_tidy$walk,
type = 'scatter', mode = 'lines+markers', name = 'Walkability index',
yaxis = "y2", color = I('black')
) %>%
layout(#legend = list(x = 0.1, y = 0.9),
yaxis = list(title = '% with health outcome'),
yaxis2=list(side="right",overlaying="y", title = "Average walkability index"),
xaxis = list(title = 'Health outcome'),
barmode = 'stack',
shapes = list(
list(type = "rect",
fillcolor = "navy", line = list(color = "navy"), opacity = 0.15,
x0 = -0.5, x1 = 62, xref = "x",
y0 = 0, y1 = 5.75, yref = "y2"),
list(type = "rect",
fillcolor = "blue", line = list(color = "blue"), opacity = 0.15,
x0 = -0.5, x1 = 62, xref = "x",
y0 = 5.76, y1 = 10.5, yref = "y2"),
list(type = "rect",
fillcolor = "teal", line = list(color = "teal"), opacity = 0.15,
x0 = -0.5, x1 = 62, xref = "x",
y0 = 10.51, y1 = 15.25, yref = "y2"),
list(type = "rect",
fillcolor = "green", line = list(color = "green"), opacity = 0.15,
x0 = -0.5, x1 = 62, xref = "x",
y0 = 15.25, y1 = 20, yref = "y2")),
annotations = list(
list(x = 65,
y = 105,
font = list(size = 10),
text = "<b>Most<br>walkable</br></b>",
xref = "x",
yref = "y",
xanchor = "right",
yanchor = "bottom",
showarrow = FALSE,
textangle = 90),
list(x = 65,
y = 75,
font = list(size = 10),
text = "<b>Above avg<br>walkable</br></b>",
xref = "x",
yref = "y",
xanchor = "right",
yanchor = "bottom",
showarrow = FALSE,
textangle = 90),
list(x = 65,
y = 45,
font = list(size = 10),
text = "<b>Below avg<br>walkable</br></b>",
xref = "x",
yref = "y",
xanchor = "right",
yanchor = "bottom",
showarrow = FALSE,
textangle = 90),
list(x = 65,
y = 8,
font = list(size = 10),
text = "<b>Least<br>walkable</br></b>",
xref = "x",
yref = "y",
xanchor = "right",
yanchor = "bottom",
showarrow = FALSE,
textangle = 90))
)
## `summarise()` has grouped output by
## 'county'. You can override using the
## `.groups` argument.
## Warning: Ignoring 60 observations
#)